package com.deparse.dpframe.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by hsy on 2016/3/8.
 */
public class DPEditText extends android.widget.EditText implements View.OnFocusChangeListener {
    private OnFocusChangeListener mOnFocusChangeListener;

    public DPEditText(Context context) {
        super(context);
        init(context);
    }

    public DPEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public DPEditText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        super.setOnFocusChangeListener(this);
    }

    @Override
    public void setText(CharSequence text, BufferType type) {
        super.setText(text, type);
        super.setSelection(super.getText().length());
    }

    @Override
    public void setOnFocusChangeListener(OnFocusChangeListener l) {
        this.mOnFocusChangeListener = l;
    }

    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        super.setCursorVisible(hasFocus);
        if (null != mOnFocusChangeListener) {
            mOnFocusChangeListener.onFocusChange(v, hasFocus);
        }
    }
}
